package com.zimu.example.controller;

import com.blade.jdbc.core.ActiveRecord;
import com.blade.mvc.annotation.GetRoute;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;
import com.blade.mvc.ui.ModelAndView;
import com.zimu.example.model.User;
import com.zimu.example.service.VCode;

import java.io.File;

/**
 * @author : zimu
 * @Date: 2018/7/19 13:28
 * @description :
 */
@Path
public class IndexController {
//    @GetRoute("/index")
////    public String index(Request request , Response response){
////        request.attribute("test" , "admin");
////        return "index.html";
////    }
    @GetRoute("/index")
    public ModelAndView index(){
//        Base.open("jdbc:mysql://localhost:3306/blade", "root", "Z1mu@hacking");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.add("user", "admin");
        modelAndView.setView("index.html");
        show();
        return modelAndView;
    }
    @GetRoute("/image")
    public String showImage(){
        return "../static/touxiang.png";
    }

    @GetRoute("/getjson")
    public void getJson(Response response) {
        response.json("{\"status\": 200}");
    }

    @GetRoute("/download")
    public void download(Response response) throws Exception {
        response.download("a.txt", new File("C:/Users/zimu/Desktop/ip.txt"));
    }

    @GetRoute("/insert")
    public void insert(){
        User user = new User();
        user.setUsername("test");
        user.setPassword("123456");
        user.setAge(11);
        user.setRealName("123");
        ActiveRecord activeRecord = new ActiveRecord();
        System.out.println(activeRecord.page(1,1));
    }

    public void show(){
        System.out.println(new User().findAll());
    }

    @GetRoute("/screenshot")
    public String screenshot(){
        return "screenshot";
    }

    @GetRoute("/vcode")
    public void vcode(Request request, Response response){
        VCode vCode = new VCode();
        vCode.doGet(request, response);
    }
}
